﻿# OTableau : WYSIWYG editor for OT tableaux, generating LaTeX code
# Version: 0.6.4
# Date: 06/03/01
# Copyright (C) 2006 Julien Eychenne
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 
# MA  02110-1301, USA.

# History: OTableau started its life as a quick and dirty Perl script. It is now
# a hopefully much cleaner python application.
import sys
from Interface import *
import OTFile
import os


refresh = False

root = Tk()
root.title('OTableau')

gmr = GUIAbsoluteTableau(root)
gmr.pack()

# Prevent console from showing up
# if hasattr(sys, 'frozen'):
#   root.tk.call('console', 'hide')
try: # if we are in a .app, hide the console (TODO:Unless debugging is on)
    root.tk.call('console', 'hide')
except TclError:
    pass

# Better looking aqua interface
# problems with cell graying, though...
# if sys.platform == 'darwin':
#   root.tk.call('package', 'require', 'tile')
#   root.tk.call('namespace', 'import', '-force', 'ttk::*')
#   root.tk.call('tile::setTheme', 'aqua')

# The user can drop an OTABLEAU or CSV file
try:
    f = sys.argv[1]
    extension = f.split('.')[-1]
    if extension == 'otableau' or extension == 'OTABLEAU':
        refresh = True
        infile = OTFile.OTableauFile(f)
        gmr.gmr = infile.getOTGrammar()
        gmr.gmr.isEvaled = False
    elif extension == 'csv' or extension == 'CSV':
        refresh = True
        gmr.gmr = OTFile.readFromCSV(f)
        gmr.gmr.isEvaled = False
except IndexError: pass

if refresh:
    gmr.gmr.initialize()
    gmr.redraw()
    
# Find Adobe Acrobat on Windows. This check can be disabled by turning
# 'check_acrobat' to 'no' in the config file.
if sys.platform[:3] == 'win' and gmr.params['check_acrobat'] == 'yes':
    foundReader = False
    root = ''
    for disk in ('C:', 'D:', 'E:','F:','G:','H:'): # Should be enough!
        if  os.path.exists(disk + os.sep + 'Program Files'):
            root = disk + os.sep + 'Program Files'
            break
    if root == '': 
        gmr.error('I could not find your "Program Files"')
    reader = ''
    root += '\\Adobe'
    if os.path.exists(root):
        for dir in os.listdir(root):
            if dir[:7] == 'Acrobat':
                reader = root + os.sep + dir + '\\Reader\\AcroRd32.exe'
                break
        if os.path.exists(reader):
            gmr.params['win_pdf_viewer'] = '"%s"' % reader
            foundReader = True
        else: gmr.error("Problem finding Acrobat in " + root)
    else: gmr.error("Acrobat is not installed or is not in the standard location.") 
    gmr.params['win_pdf_reader_found'] = foundReader
 

gmr.mainloop()
